import { createSlice } from "@reduxjs/toolkit";
const cart = createSlice({
  name: "cart",
  initialState: {
    list: [],
    num: 0,
  },
  reducers: {
    addnums(state) {
      state.num += 1;
    },
    addcart(state, actions) {

      let list = state.list
      list = list.push(actions.payload)
      
    },
    changenum(state,actions){
      let list = state.list
      list[actions.payload.i].num = actions.payload.value
    },
    del(state,actions){
      console.log(actions);
      
      let list = state.list
      list.splice(actions.payload.index,1)

    }
  },
});
export const { addcart, addnums, changenum,del} = cart.actions;
export default cart.reducer;
